package com.red.wine.adapter;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.red.wine.R;
import com.red.wine.adapter.TasteAdapter.Composites;
import com.red.wine.model.TasteInfo;
import com.red.wine.model.TopInfo;
import com.red.wine.util.PrefsUtils;
import com.red.wine.util.StringUtil;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {

	public int getCount() {
		// TODO Auto-generated method stub
		 return datasource.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return datasource.get(position);	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		Composites composites= null;  
		if( convertView == null ) {
              composites = new Composites();
              convertView = LayoutInflater.from(context).inflate(R.layout.taste_top_item_layout,null);
            composites.icon = (ImageView) convertView.findViewById(R.id.taste_top_item_img);
       }else {//在convertView不为空时，Recycler根据旧的item根据数据进行置换，从而直接使用旧的item即可！
    	   composites =  (Composites) convertView.getTag();
       }
		 
		composites.icon.setImageBitmap(datasource.get(position));
       return convertView;
	}
	private List<Bitmap> datasource;
	Context context;
	public ImageAdapter(Context context, List<Bitmap> datasource) {
		this.context = context;
		this.datasource = datasource;
		
	}
	 
	public class Composites {
		public ImageView icon;
	}
}
